<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateTenantUserDepartmentTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('tenant_user_department', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '租户用户部门表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => 'ID'])
            ->addColumn('tenant_user_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '租户成员id'])
            ->addColumn('department_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '部门id'])
            ->addColumn('created', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建人'])
            ->addIndex(['tenant_user_id'], ['name' => 'idx_tenant_user'])
            ->addIndex(['department_id'], ['name' => 'idx_department'])
            ->addIndex(['department_id', 'tenant_user_id'], ['name' => 'idx_department_tenant_user', 'type' => 'unique'])
            ->save();
    }

    public function down()
    {
        $this->table('tenant_user_department')->drop();
    }
}
